package com.beyond.pm.ui.home.drawer

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.ScaffoldState
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.beyond.pm.R
import com.beyond.pm.bean.RouteScreenParameter
import kotlinx.coroutines.launch

/**
 * @author chen
 * @time 2023/6/8 16:49
 * @name ProjectManage
 * @class describe
 */

private val screens = listOf(
    RouteScreenParameter.DmlLog,
    RouteScreenParameter.SystemSetting,
    RouteScreenParameter.Test,
    RouteScreenParameter.About,
)

@Composable
fun AppDrawer(
    scaffoldState: ScaffoldState,  navigate: (nav: String) -> Unit
) {
    val coroutineScope = rememberCoroutineScope()
    ModalDrawerSheet(Modifier.fillMaxWidth()) {
        Spacer(modifier = Modifier.height(16.dp))
        Image(
            painter = painterResource(id = R.mipmap.ic_launcher_round),
            contentDescription = null,
            modifier = Modifier
                .align(Alignment.CenterHorizontally)
                .size(80.dp)
        )
        Spacer(Modifier.height(24.dp))
        screens.forEach {
            NavigationDrawerItem(
                label = { Text(stringResource(id = it.bean.labelId)) },
                icon = { Icon(it.bean.icon, null) },
                selected = false,
                onClick = {
                    coroutineScope.launch {
                        scaffoldState.drawerState.close()
                    }
                    navigate(it.bean.routerStr)
                },
                modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
            )
        }
    }
}